package com.example.springioc.Controller;

import com.example.springioc.Component.User;
import com.example.springioc.Service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {
    //注入依赖
    //方法一：注解注入
//    @Autowired
//    private UserService service;
    //方法二：构造方法注入
//    private UserService service;
//    public UserController(UserService service){
//        this.service=service;
//    }
    //方法三：setter注入
    private UserService service;
@Autowired
    public void setService(UserService service) {
        this.service = service;
    }
    //注入User
    @Autowired
    @Qualifier("user2")
    //@Resource(name = "user2")
    private User Uers;

    public void sayhi(){
        service.doService();
        System.out.println("hi,UserController");
        System.out.println(Uers);
    }
}
